<template>
    <!-- packageA/pages/setStoreSound/setStoreSound.wxml -->
    <view class="container" :style="isIpx ? 'padding-bottom:168rpx' : 'padding-bottom:120rpx'">
        <view class="title">留空或不设置，设备将播放预设音频</view>
        <view class="title">禁止播放违反法律/伦理的非法文本</view>
        <view class="form">
            <view class="line">
                <label>欢迎语：</label>
                <view class="right">
                    <textarea v-model="welcomeText" type="text" placeholder="最大150个字" />
                </view>
            </view>
            <view class="tips">注:订单开始1分钟时播报</view>
            <view class="line">
                <label>到期前30分钟</label>
                <view class="right">
                    <textarea v-model="endText30" type="text" placeholder="最大150个字" />
                </view>
            </view>
            <view class="line">
                <label>到期前5分钟</label>
                <view class="right">
                    <textarea v-model="endText5" type="text" placeholder="最大150个字" />
                </view>
            </view>
            <view class="line">
                <label>深夜提醒</label>
                <view class="right">
                    <textarea v-model="nightText" type="text" placeholder="最大150个字" />
                </view>
            </view>
            <view class="tips">注:凌晨第一个整点播报</view>
        </view>
        <!-- 底部按钮 -->
        <view :class="'submit border-primary ' + (isIpx ? 'fix-iphonex-button' : '')">
            <button hover-class="button-click" class="color-primary cancel" @tap="cancel">取消</button>
            <button hover-class="button-click" class="bg-primary" @tap="submit">保存</button>
        </view>
    </view>
</template>

<script>
// packageA/pages/setStoreSound/setStoreSound.js
const app = getApp();
var http = require('../../../utils/http');
var util1 = require('../../../utils/util.js');
export default {
    data() {
        return {
            storeId: '',
            welcomeText: '',
            endText30: '',
            endText5: '',
            nightText: '',
            isIpx: false
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.setData({
            storeId: Number(options.storeId)
        });
        this.getInfoData();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        getInfoData: function () {
            return new Promise((r, t) => {
                var that = this;
                //if (app.globalData.isLogin)
                {
                    http.request(
                        '/member/store/getStoreSoundInfo/' + that.storeId,
                        '1',
                        'get',
                        {},
                        app.globalData.userDatatoken.accessToken,
                        '',
                        function success(info) {
                            console.info(info);
                            if (info.code == 0) {
                                that.setData({
                                    welcomeText: info.data.welcomeText,
                                    endText30: info.data.endText30,
                                    endText5: info.data.endText5,
                                    nightText: info.data.nightText
                                });
                            } else {
                                uni.showModal({
                                    content: '请求服务异常，请稍后重试',
                                    showCancel: false
                                });
                            }
                        },
                        function fail(info) {}
                    );
                }
            });
        },

        // 保存
        submit: function () {
            let that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/store/saveStoreSoundInfo',
                    '1',
                    'post',
                    {
                        storeId: that.storeId,
                        welcomeText: that.welcomeText,
                        endText30: that.endText30,
                        endText5: that.endText5,
                        nightText: that.nightText
                    },
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info(info);
                        if (info.code == 0) {
                            uni.showToast({
                                title: '设置成功',
                                icon: 'success'
                            });
                            setTimeout(() => {
                                uni.navigateBack({
                                    delta: 1
                                });
                            }, 1000);
                        } else {
                            uni.showModal({
                                content: info.msg,
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        cancel() {
            console.log('占位：函数 cancel 未声明');
        }
    }
};
</script>
<style>
@import './setStoreSound.css';
</style>
